import basegraphunit from './basegraphunit.js'
import coorPkg from '../../struct/coord.js'
import fillinfo from '../fillinfo.js';

class Cube extends basegraphunit.BaseGraphUnit {
    constructor() {
        super();
        this.pos = new coorPkg.PointPos();
        this.x = 0;
        this.y = 0;
        this.angle = 0;
        this.width = 0;
        this.height = 0;
        this.depth = 0;
        this.coverFillDef = null;
        this.rightFillDef = null;
    }

    translateSubInfo(tx,ty){
        this.x += tx;
        this.y += ty;
    }

    toJson() {
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["x"] = this.x;
        jsonobj["y"] = this.y;
        jsonobj["width"] = this.width;
        jsonobj["height"] = this.height;
        jsonobj["depth"] = this.depth;

        if (this.coverFillDef){
            jsonobj["coverFillDef"] = this.coverFillDef.toJson();
        }

        if (this.rightFillDef){
            jsonobj["rightFillDef"] = this.rightFillDef.toJson();
        }

        return jsonobj;
    }
    fromJson(obj) {
        super.fromJson(obj);
        this.x = obj["x"];
        this.y = obj["y"];
        this.pos.x = this.x;
        this.pos.y = this.y;

        this.width = obj["width"];
        this.height = obj["height"];
        this.depth = obj["depth"];
        
        let tmp = obj["coverFillDef"];
        if (tmp){
            this.coverFillDef = new fillinfo.LGXFillDefInfo();
            this.coverFillDef.fromJson(tmp);
        }

        tmp = obj["rightFillDef"];
        if (tmp){
            this.rightFillDef = new fillinfo.LGXFillDefInfo();
            this.rightFillDef.fromJson(tmp);
        }
    }

    cloneCopy() {
        var pNewInfo = new Cube();
        super.cloneCopy(pNewInfo);
        pNewInfo.x = this.x;
        pNewInfo.y = this.y;
        pNewInfo.width = this.width;
        pNewInfo.height = this.height;
        pNewInfo.depth = this.depth;

        if (this.coverFillDef){
            pNewInfo.coverFillDef = new fillinfo.LGXFillDefInfo();
            pNewInfo.coverFillDef.clone(this.coverFillDef);
        }

        if (this.rightFillDef){
            pNewInfo.rightFillDef = new fillinfo.LGXFillDefInfo();
            pNewInfo.rightFillDef.clone(this.rightFillDef);
        }

        return pNewInfo;
    }
}

export default { Cube }